﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GoldMantis.Web.UI.WebControls;
using System.Data;

using TimKen.BussLogic;
using NineRays.WebControls;

namespace TimKen.Web.Admin.ProductCategory
{
    public partial class ProductCategory_List : TimKen.App.AdminPage
    {
        PCategoryManager categoryManager = new PCategoryManager();
        public override string ActionCode
        {
            get
            {
                return "89";
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.QueryString["Act"] == "Delete" && Request.QueryString["categoryId"] != null)
                {
                    int categoryId = Convert.ToInt32(Request.QueryString["categoryId"]);
                    if (categoryId ==  PCategoryManager.otherCategoryID)
                    {
                        //为“其他”分类，系统默认分类，无法删除
                        Alert(GetLangString("SystemCategoryUnDeleteable"));
                    }
                    else
                    {

                        bool result = categoryManager.Delete(categoryId);
                        if (categoryManager.Delete(categoryId))

                            Alert(categoryManager.ValidMessage, "ProductCategory_List.aspx");
                        else
                            Alert(categoryManager.ValidMessage, "ProductCategory_List.aspx");
                    }
                }
                BindTreeListView();
            }
        }

        private void BindTreeListView()
        {
            DataSet ds = categoryManager.GetList(LanguageWhereStr);
            
            DataRow  dr = ds.Tables[0].NewRow();
            dr["CategoryName"] = "产品分类";
            dr["LanguageID"] = LanguageID;
            dr["ParentID"] = DBNull.Value;
            dr["CategoryID"] = 0;

            ds.Tables[0].Rows.Add(dr);
           
            this.FlyTreeView1.DataSource = FlyTreeView.ConvertTabularDataToHierarchical(ds, "CategoryID", "ParentID");
            this.FlyTreeView1.DataBind();
        }

   

    }
}
